package com.bigdatastudio.admin.controller;

import com.bigdatastudio.admin.service.IMenuService;
import com.bigdatastudio.auth.server.IRoleService;
import com.bigdatastudio.auth.server.IUserRoleService;
import com.bigdatastudio.auth.utils.TokenUtil;
import com.bigdatastudio.common.Utils.R;
import com.bigdatastudio.common.entity.Menu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    IMenuService menuService;
    @Autowired

    IUserRoleService userRoleService;

    @Autowired
    IRoleService roleService;
    /**
     * 权限管理
     *
     * @return 权限信息
     */
    @CrossOrigin("true")
    @GetMapping("getRouters")
    public R getRouters()
    {
        Integer userId = TokenUtil.getJwtUser().getId();
        List<Menu> menus = menuService.getMenuByUserId(userId);
        return R.ok(menus,"路由信息封装完成");
    }


    @CrossOrigin("true")
    @GetMapping("getUserRoles")
    public R getUserRoles()
    {
        return R.ok(userRoleService.list(),"拿到了用户角色表");
    }

    @CrossOrigin("true")
    @GetMapping("getRoles")
    public R getRoles()
    {
        return R.ok(roleService.list(),"拿到了角色表");
    }
}
